package com.jxust.hr.service.impl;


import com.jxust.hr.dao.ManagerMapper;
import com.jxust.hr.service.ManagerService;
import org.springframework.stereotype.Service;
import cn.hutool.core.date.DateUtil;

import javax.annotation.Resource;

import java.util.*;

@Service
public class ManagerServiceImpl implements ManagerService {

    @Resource
    ManagerMapper managerMapper;


    @Override
    public  List<Map<String,Object>> getTodos(String username){
        return managerMapper.getTodos(username);
    }

    @Override
    public int setTodo(String username,String time,String tag,String todo){
        return managerMapper.setTodo(username,time,tag,todo);
    }

    @Override
    public  List<Object> selectAttendanceCount(){
        Date date=DateUtil.beginOfWeek(new Date());//这个礼拜获取星期一
        List<Object> list =new ArrayList<>();

        int day= DateUtil.dayOfWeek(new Date());//获得指定日期是星期几，1表示周日，2表示周一
        if(day==1)day=6; //周日要放到这个礼拜的最后去
        if(day>6)day=6; //假数据里有星期六的数据,过滤掉

        for(int i=day-1;i>0;i--){
            Map<String,Object> map=new HashMap<>();
            map.put("date",DateUtil.dayOfWeekEnum(date).toChinese());//获取当前时间是星期几
            int sum=managerMapper.selectEmployeeSum();
            int absent_count=managerMapper.selectEmployeeTypeCount(date,"缺勤");
            int late_count=  managerMapper.selectEmployeeTypeCount(date,"迟到");
            int early_count=managerMapper.selectEmployeeTypeCount(date,"早退");

            int attend_count= sum-absent_count-late_count-early_count; //计算出勤的总人数
            map.put("sum",sum);
            map.put("absent_count",absent_count);
            map.put("late_count",late_count);
            map.put("early_count",early_count);

            map.put("attend_count",attend_count);


            list.add(map);
            date= DateUtil.offsetDay(date,1);  //偏移天,这里是加一天
        }
        return list;

    }

    @Override
    public  List<Map<String,Object>> selectAttendanceInfo(){
        List<Map<String,Object>> list= managerMapper.selectAttendanceInfo();
        return list;
    }

    @Override
    public List<String> getPositions(){
        return managerMapper.getPositions();
    }

    @Override
    public List<Map<String,Object>> getMembers(String name,String position,int limit, int offset){
        return managerMapper.getMembers(name,position,limit,offset);
    }

    @Override
    public List<Object> getEmployeeInfoAll(String employeeId){
        List<Object> list =new ArrayList<>();
        list.add(managerMapper.getEmployeeInfoById(employeeId));//通过Id查找员工-基本信息

        Map<String,Integer> mapAttendanceNum=new HashMap<>();//集合定义时如果不使用泛型，就默认是Object类型
        mapAttendanceNum.put("absent_count",managerMapper.getAttendanceNumById(employeeId,"缺勤"));
        mapAttendanceNum.put("late_count",managerMapper.getAttendanceNumById(employeeId,"迟到"));
        mapAttendanceNum.put("early_count",managerMapper.getAttendanceNumById(employeeId,"早退"));
        list.add(mapAttendanceNum);//通过Id查找员工-考勤信息

        list.add(managerMapper.selectEmployeePositionInfo(employeeId));//通过ID查找员工的一些 在职表现

        return list;
    }

    @Override
    public List<Map<String,Object>> getEmployeeList(){
        return managerMapper.getEmployeeList();
    }

    @Override
    public int setTasks(String task,String start_time,String end_time,String executors){
        return managerMapper.setTasks(task,start_time,end_time,executors);
    }
    @Override
    public List<Map<String,Object>> getTasks(){
        return  managerMapper.getTasks();
    }

    @Override
    public int setTaskCompletion(Integer id,String completion){
        return managerMapper.setTaskCompletion(id,completion);
    }

    @Override
    public List<Map<String,Object>> getEvaluationList(){
        return managerMapper.getEvaluationList();

    }

    @Override
    public int setEvaluation(String employeeId,String working_performance,String violation,String contribution,String others){
        return managerMapper.setEvaluation(employeeId,working_performance,violation,contribution,others);
    }

    @Override
    public  Map<String,Object> getEmployeeCompanyById(String employeeId){

        Map<String,Object> map=new HashMap<>();
        map.put("basicInfo",managerMapper.getEmployeeAllInfoById(employeeId));//通过id查找员工个人信息
        map.put("currentCompany",managerMapper.getCurrentCompany(employeeId));
        map.put("lastCompanies",managerMapper.getLastCompanies(employeeId));

        return map;
    }
}
